<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    canvas {
      border: 1px solid rgba(0, 0, 200, 0.5);
      height: 500px;
      width: 500px;
    }
  </style>
</head>

<body>
  <canvas height="500" width="500"></canvas>
</body>
<script>
  const canvas = document.querySelector('canvas');

  const ctx = canvas.getContext('2d');

  console.log('canvas', canvas)

  // 绘制多边形
  function regularShape (edges = 3, x, y, step) {
    const ret = [];

    const dalta = Math.PI * (1 - (edges - 2) / edges);
    let p = new Vector2D(x, y);
    const dir = new Vector2D(step, 0);
    ret.push(p);
    for (let i = 0; i < edges; i++) {
      p = p.copy().add(dir.rotate(delta))
      ret.push(p);
    }
    return ret;
  }
</script>

</html>